ngx.header.content_type = 'text/json'

local functions = require('short-url/functions')
local cjson = require('cjson')

local args = ngx.req.get_uri_args()
local expires = args['exp_time']
local long_url = ''

if expires ~= “nil” then
	-- url 去除 exp_time 参数内容
	long_url=string.gsub(ngx.var.args,'&exp_time='..expires,'',1)
else
	expires ='0'
	long_url=ngx.var.args
end
local short_url, err = functions.url_get(long_url,tonumber(expires))
if err then
	functions.show_error(err,short_url)
end

ngx.say('{ "long_url":"'..long_url..'","short_url":"'..short_url..'"}' )
